#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2021/7/20 11:33
# @Author  : Samge
from PyQt5.QtWidgets import QWidget
from itkz.resources.utils.log import Log


class BaseQWidget(QWidget):
    
    itkz_db = None

    def __init__(self):
        super().__init__()
        self.setup_db()

    def setup_db(self):
        """
        初始化数据库对象，子类需要根据需要进行设置
            self.policy_db = self.policy_db or PolicyDb()
            self.policy_source_db = self.policy_source_db or PolicySourceDb()
            self.policy_files_db = self.policy_files_db or PolicyFilesDb()
            self.policy_dtl_style_db = self.policy_dtl_style_db or PolicyDtlStyleDb()
            self.policy_source_rule_db = self.policy_source_rule_db or PolicySourceRuleDb()
            self.policy_ignore_db = self.policy_ignore_db or PolicyIgnoreUrlDb()
            self.policy_todo_db = self.policy_todo_db or PolicyTodoDb()
        :return:
        """
        pass

    def close_db(self):
        Log().getlog().info("关闭数据库连接")
        self.close_with_db(self.itkz_db)

    def close_with_db(self, _db):
        if _db:
            _db.close_connect()
            _db = None

    def name(self):
        return self.__class__.__name__

    # 添加 复写 显示窗口函数
    def showEvent(self, e):
        # Log().getlog().info("窗口显示")
        pass

    def hideEvent(self, e):
        # Log().getlog().info("窗口隐藏")
        pass

    def mouseMoveEvent(self, e):
        # Log().getlog().info("鼠标移动窗口")
        pass

    def moveEvent(self, e):
        # Log().getlog().info("窗口尺寸修改")
        pass

    def resizeEvent(self, e):
        # Log().getlog().info("窗口大小改变")
        pass

    def closeEvent(self, e):
        # Log().getlog().info("窗口关闭")
        pass
